//
// Created by Administrator on 2022/2/6.
//

#ifndef CPP_LEARNING_LEETCODE979_H
#define CPP_LEARNING_LEETCODE979_H
#include "treenode.h"
#include <math.h>
class Solution979 {
public:

    int moveNUm = 0;

    /**
     *  返回值
     *      +1  向上送一个
     *      -1  向下借一个
     *      0   正好
     */
    int postOrder(TreeNode* node){
        if(node == nullptr) return 0;

        int leftnum = postOrder(node->left);
        int rightnum = postOrder(node->right);

        int curNUm = leftnum + rightnum + node->val;
        moveNUm += abs(curNUm-1);
        return curNUm-1;
    }
    int distributeCoins(TreeNode* root) {
        postOrder(root);
        return moveNUm;
    }
};
void test979(){

}
#endif //CPP_LEARNING_LEETCODE979_H
